// miniprogram/pages/Home/Freeroom/Freeroom.js
const app = getApp();
var sev = require('../../../utils/sev.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    listData:[],
    listhide:true,
    img:'',
    jxl:[
      "J1", "J3", "J5", "J7", "J11", "J13", "J14", "J15", "S1"
    ],
    ids:[
      "1", "3", "5", "7", "11", "13", "14", "15", "S1"
    ],
    time:[
      "上午","下午","晚上","全天"
    ],
    timeids:[
      "am","pm","night","allday"
    ],
    cindex:0,
    index:0,
    btnhide:false
  },
  query(){
    var compare = function(a,b){
      return a.jsmc<b.jsmc;
    }//排序为什么不起作用？
   //console.log('q')
    var that = this;
    this.setData({btnhide:!this.data.btnhide});
    wx.setStorage({key:'freeset',data:{index:this.data.index,cindex:this.data.cindex},success(res){console.log('基础设置保存成功')}});
    wx.cloud.callFunction({
      name:'sync',
      data:{
        URL: sev.eduosEmpclass(this.data.timeids[this.data.cindex], this.data.ids[this.data.index]),
        token:app.eduOS.token
      },
      success(res){
        console.log(res)
        var ilist = res.result[0].jsList.sort(compare);
        //var tlist = ilist.sort(function(a,b){return a.jsh<b.jsh});
        //console.log(tlist);
      that.setData({'listData':ilist,listhide:!that.data.listhide})},fail(res){console.log(res)}
    })
  },
  timechange(e){
    this.setData({cindex:e.detail.value});
  },
  PickerChange(e){
    this.setData({index:e.detail.value})
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    this.setData({ img: app.globalData.imgList.roombg });
    //配置用户常用设置
   wx.getStorage({key:'freeset',success:function(res){that.setData({index:res.data.index,cindex:res.data.cindex})}});
    //console.log(app.eduOS.token)
  }
})